package com.cyou.nad.datastore.query.dialect;

import com.cyou.nad.dao.Pagination;

public class MySqlDialect implements Dialect {

	public String getLimitString(String sql, boolean hasOffset) {
		return new StringBuilder(sql.length() + 20).append(sql).append(hasOffset ? " limit ?, ?" : " limit ?").toString();
	}

	@Override
	public Object[] getLimitParam(int pageNo,int pageSize,boolean hasOffset) {
		if(hasOffset)
			return new Object[]{getStartOfPage(pageNo,pageSize),pageSize};
		return new Object[]{pageSize};
	}

	int getStartOfPage(int pageNo, int pageSize) {
		return (pageNo - 1) * pageSize;
	}
}
